package c.e.a.b.f.b;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Pair;
import b.i.b.f;
import c.e.a.b.a.a.a.a;
import c.e.a.b.b.j.c;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Objects;

/* compiled from: com.google.android.gms:play-services-measurement-impl@@18.0.0 */
public final /* synthetic */ class e6 implements Runnable {
    public final c6 a;

    public e6(c6 c6Var) {
        this.a = c6Var;
    }

    public final void run() {
        c6 c6Var = this.a;
        c6Var.g();
        if (c6Var.l().x.b()) {
            c6Var.d().m.a("Deferred Deep Link already retrieved. Not fetching again.");
            return;
        }
        long a = c6Var.l().y.a();
        c6Var.l().y.b(a + 1);
        if (a >= 5) {
            c6Var.d().i.a("Permanently failed to retrieve Deferred Deep Link. Reached maximum retries.");
            c6Var.l().x.a(true);
            return;
        }
        Pair pair;
        u4 u4Var = c6Var.a;
        u4Var.a().g();
        u4.q(u4Var.n());
        n3 z = u4Var.z();
        z.t();
        String str = z.c;
        d4 o = u4Var.o();
        o.g();
        Objects.requireNonNull((c) o.a.n);
        long elapsedRealtime = SystemClock.elapsedRealtime();
        String str2 = "";
        if (o.m == null || elapsedRealtime >= o.o) {
            c cVar = o.a.g;
            Objects.requireNonNull(cVar);
            o.o = cVar.n(str, p.b) + elapsedRealtime;
            try {
                a b = c.e.a.b.a.a.a.b(o.a.a);
                String str3 = b.a;
                o.m = str3;
                o.n = b.b;
                if (str3 == null) {
                    o.m = str2;
                }
            } catch (Exception e) {
                o.d().m.b("Unable to get advertising id", e);
                o.m = str2;
            }
            pair = new Pair(o.m, Boolean.valueOf(o.n));
        } else {
            pair = new Pair(o.m, Boolean.valueOf(o.n));
        }
        if (!u4Var.g.y().booleanValue() || ((Boolean) pair.second).booleanValue() || TextUtils.isEmpty((CharSequence) pair.first)) {
            u4Var.d().m.a("ADID unavailable to retrieve Deferred Deep Link. Skipping");
        } else {
            NetworkInfo activeNetworkInfo;
            d7 n = u4Var.n();
            n.o();
            try {
                activeNetworkInfo = ((ConnectivityManager) n.a.a.getSystemService("connectivity")).getActiveNetworkInfo();
            } catch (SecurityException unused) {
                activeNetworkInfo = null;
            }
            Object obj = (activeNetworkInfo == null || !activeNetworkInfo.isConnected()) ? null : 1;
            if (obj == null) {
                u4Var.d().i.a("Network is not available for Deferred Deep Link request. Skipping");
            } else {
                Object url;
                t9 t = u4Var.t();
                u4Var.z();
                String str4 = (String) pair.first;
                long a2 = u4Var.o().y.a() - 1;
                Objects.requireNonNull(t);
                try {
                    f.N(str4);
                    f.N(str);
                    r6 = new Object[4];
                    r6[0] = String.format("v%s.%s", new Object[]{Long.valueOf(33025), Integer.valueOf(t.y0())});
                    r6[1] = str4;
                    r6[2] = str;
                    r6[3] = Long.valueOf(a2);
                    str4 = String.format("https://www.googleadservices.com/pagead/conversion/app/deeplink?id_type=adid&sdk_version=%s&rdid=%s&bundleid=%s&retry=%s", r6);
                    if (str.equals(t.a.g.c("debug.deferred.deeplink", str2))) {
                        str4 = str4.concat("&ddl_test=1");
                    }
                    url = new URL(str4);
                } catch (IllegalArgumentException | MalformedURLException e2) {
                    t.d().f.b("Failed to create BOW URL for Deferred Deep Link. exception", e2.getMessage());
                    url = null;
                }
                d7 n2 = u4Var.n();
                x4 x4Var = new x4(u4Var);
                n2.g();
                n2.o();
                Objects.requireNonNull(url, "null reference");
                n2.a().x(new f7(n2, str, url, x4Var));
            }
        }
    }
}
